<?php 
include('./fun.php');
$conn=my_sql($cfg);

$re=adm_login();
if($re['err']=='no_login'){
$re=user_login();
if($re['err']=='no_login'){direct('login.php?t='.time());exit;}
if($re['err']!='ok'){die($re['err']);}
$user=$re['user'];
$shop_id=$re['shop_id'];

}else{
if($re['err']!='ok'){die($re['err']);}
$adm=$re['adm'];
}
$set=get_set();


$url=get('url');



if($adm){
$left['首页']=array('icon'=>'icon-diannao','url'=>'main');
if(!$url){$url='main';}

$left['门店管理']=array('icon'=>'icon-dianpu','url'=>'shop_list');
$left['用户管理']=array('icon'=>'icon-xuanzhonghaoyou','url'=>'user_list');
$left['浏览记录']=array('icon'=>'icon-shouyi','url'=>'view_list');
$left['Emoji图标']=array('icon'=>'icon-chongwu','url'=>'emoji');
$left['投诉建议']=array('icon'=>'icon-chat_bubble_','url'=>'ts_jy');
$left['帮助文档']=array('icon'=>'icon-help-circle-outline','url'=>'help_list');



}else{
$left['首页']=array('icon'=>'icon-diannao','url'=>'user_main');
if(!$url){$url='user_main';}
$left['订单管理']=array('icon'=>'icon-dingdan1','url'=>'order_list','query'=>'&left_s=待发货');
$left['订单管理']['menu']['待发货']['url']='order_list';
$left['订单管理']['menu']['售后订单']['url']='order_list';
$left['订单管理']['menu']['售后订单']['query']='&state=99';

$left['订单管理']['menu']['已配送发货']['url']='order_list';
$left['订单管理']['menu']['已配送发货']['query']='&state=5';

$left['订单管理']['menu']['已完成']['url']='order_list';
$left['订单管理']['menu']['已完成']['query']='&state=10';


$left['活动列表']=array('icon'=>'icon-pingjia','url'=>'hd_list');

//$left['资金管理']=array('icon'=>'icon-shouyi','url'=>'money');


$left['商品管理']=array('icon'=>'icon-gouwudai','url'=>'pros');
$left['图片管理']=array('icon'=>'icon-tupian','url'=>'img');

$left['员工列表']=array('icon'=>'icon-pintuan','url'=>'emp_list');
$left['团长列表']=array('icon'=>'icon-pintuan','url'=>'tz_list');
}







if($adm){
$left['系统设置']=array('icon'=>'icon-shezhi','url'=>"set",'query'=>'&left_s=系统设置');
$left['系统设置']['menu']['系统设置']['url']='set';
$left['系统设置']['menu']['模板消息']['url']='temp';
$left['系统设置']['menu']['管理员管理']['url']='adm';
$left['系统设置']['menu']['修改密码']['url']='password';
$left['系统设置']['menu']['退出登录']['ac']='loginout()';
$left['系统设置']['menu']['打印机管理']['url']='printer_list';
}






$blue='#10218b';
//print_r($set);
if($set){
$cfg['webname']=$set['webname'];
if($set['logo']){$cfg['logo']=$set['logo'];}
}



?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0">
<meta name="Cache-control" content="no-tranform">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="Author" content="web_author">
<meta name="apple-mobile-web-app-title" content="">
<meta name="screen-orientation" content="portrait">
<meta name="x5-orientation" content="portrait">
<meta name="browsermode" content="application">
<meta name="x5-page-mode" content="app">
<meta name="HandheldFriendly" content="true">
<meta name="msapplication-tap-highlight" content="no">
<title><?php echo $cfg['webname'].'管理中心';?></title>
<script src="./jquery.js"></script>
<script src="./jqm.js"></script>
<script src="./chart.js"></script>
<script src="./fun.js?t=<?php echo $cfg['time'];?>"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/34.0.0/classic/ckeditor.js"></script>
<link type="text/css" rel="stylesheet" href="./style.css?t=12321">



</head>

<style>
body{font-size:12px}
nav{position:fixed;width:100%;height:50px;line-height:50px;background:#262F3E;z-index:1000;padding-left:70px;padding-right:20px;}
left{position:fixed;width:140px;left:0;top:0;height:100vh;background:#262F3E;z-index:800;color:#fff;padding-top:50px;padding-bottom:30px;overflow:hidden;overflow-y:auto}
main{position:fixed;width:100%;padding-left:140px;padding-top:50px;padding-right:0px;padding-bottom:20px;z-index:50;height:100vh;overflow:auto;overflow-x:hidden;background:#efefef}
bottom{background:#fff;position:fixed;width:100%;height:40px;line-height:40px;padding-left:100px;bottom:0;z-index:600;color:#666;font-size:14px;text-align:center;}
main_box{float:left;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;padding-right:0px;}
left::-webkit-scrollbar{width:5px;background:#262F3E !important;border-radius:3px}
left::-webkit-scrollbar-thumb {border-radius:2px;-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);background: #262F3E;}
nav_title{float:left;font-weight:bold;font-size:18px;color:#fff;text-shadow:1px 1px #000;margin-top:-3px}
nav_icon{float:right;margin-right:20px;}
nav_icon icon{float:right;font-size:20px !important;margin-left:10px;text-shadow:1px 1px #000;}.icon-mb_zhuxiao{color:#f44;}
nav_icon icon:hover{color:#f44;}
nav logo{width:35px;height:35px;position:absolute;left:15px;top:5px;border-radius:10px}

left_box{float:left;width:100%;min-height:50px;line-height:50px;text-align:center;}
.left_main{float:left;width:100%;height:50px;line-height:50px;padding-left:40px;padding-right:20px;}
.left_main icon{position:absolute;width:50px;height:50px;line-height:50px;text-align:center;font-size:24px;left:0;top:0;}
.left_main text{color:#000;height:50px;line-height:50px;color:#fff;overflow:hidden;font-size:15px}
.left_bottom{position:absolute;bottom:0;left:0;}

left a{color:#fff;}
left a:hover{color:#fff;background:rgba(255,255,255,.05);}
left a:hover text{display:block;}
left .is_select icon,left .is_select text{color:#006eff;}
.left_mini in_box{display:none !important;}
left .is_select left_item{display:block}

h1{float:left;width:100%;height:60px;line-height:60px;margin:0;padding:0;font-size:24px;padding-left:20px;border-bottom:1px solid #eee;}
help{float:left;width:100%;line-height:20px;font-size:14px;margin-top:5px;color:#666}
warn{float:left;width:100%;height:36px;line-height:36px;background:rgba(255,0,0,0.05);color:orange;padding-left:20px;padding-right:10px;overflow:hidden;}

main_index{float:left;width:100%;padding:10px;padding-left:20px;}
main_index a{transition:all .3s ease-in-out;float:left;padding-left:15px;padding-right:15px;height:36px;line-height:36px;background:#09c;color:#fff;border-radius:3px;margin-right:10px;}
main_index a:hover{background:#f44;color:#fff;}


h2{margin:0;margin-top:10px;border-bottom:1px solid #ccc;padding-bottom:10px;}


.bt_color{background:rgab(0, 137, 151, 0.5)}
.bt_color:hover{background:#00c8dc}
.blue{background:#10218b;color:#fff;}
.green{background:green;color:#fff; }
.red{background:crimson;color:#fff;}
.gay{background:#999}

.page_num{width:30px;height:30px;line-height:30px;padding:0;text-align:center;margin-top:10px}
page{float:left;width:100%;padding:10px;text-align:center;margin-top:20px;display:flex;justify-content:center;}
page a{border-radius:3px;background:#fff;float:left;width:32px;height:32px;margin:8px;line-height:32px;font-size:14px;color:#333;box-shadow:0 2px 4px 0 rgb(54 58 80 / 32%);}
page a:hover{background:#006eff;color:#fff;}
page .is_select{background:#006eff;color:#fff}


no_data{float:left;width:100%;margin-top:40px;text-align:center;}
no_data_text{float:left;width:100%;margin-top:10px;text-align:center;font-size:20px;}



date_box{float:left;width:280px;padding:0;height:auto}
date_handle{float:left;width:100%;height:28px;line-height:28px;background:#efefef;}
date_handle icon{position:absolute;left:10px;z-index:100;height:28px;line-height:28px;font-size:20px}
date_handle text{float:left;width:100%;text-align:center;}
date_box w{float:left;width:40px;height:30px;text-align:center;line-height:30px;}
date_box a{float:left;width:40px;height:30px;line-height:30px;text-align:center;}
date_box .gay{color:#999;background:none}
date_box .icon-chevron-right{right:0px;z-index:100;left:auto}
date_box .now{color:crimson;}
date_box .select{background:rgba(25,0,255,0.1);color:green}

select_date_box{float:left;width:100%}
left_item{float:left;width:100%;height:36px;line-height:36px;font-size:13px;display:none;}
.left_item_select{background:#006eff;} 
left_item a{float:left;width:100%;height:36px;line-height:36px;font-size:13px;padding-left:20px}
left_box .jt{position:absolute;right:10px;height:50px;line-height:50px;}


hh{float:left;width:100%;height:50px;background:#fff;line-height:50px;padding-left:20px;padding-right:20px;}
hh b{float:left;font-size:18px;font-weight:bold}

index{float:left;width:100%;}
index a{float:left;height:36px;line-height:36px;padding-left:15px;padding-right:15px;background:#fff;margin-right:10px;color:#333}
index .b{background:#006eff;color:#fff;}
mm{float:left;width:100%;padding:20px;}
index .b:hover{background:#262F3E;}
index num{position:absolute;width:18px;height:18px;border-radius:50%;background:crimson;color:#fff;top:-3px;right:-3px;line-height:18px;font-size:10px;text-align:center;}
index a:hover{background:#262F3E;color:#fff;}
index .select{background:crimson;color:#fff;}
index .t{background:none;color:#006eff}
index .t:hover{background:none;color:crimson;}
index input{float:left;height:36px;line-height:36px;padding-left:10px;padding-right:10px;background:#fff;margin-right:10px;box-shadow:0 2px 4px 0 rgb(54 58 80 / 32%);}


table{float:left;width:100%;margin-top:10px;background:#fff;text-align:center;}
th{padding-top:8px;padding:8px;background:rgba(0,0,0,.05);font-weight:normal;font-size:14px}
td{padding:10px;font-size:13px;}
table a{color:#006eff;margin-left:5px;margin-right:5px;}
table a:hover{color:crimson;}
tr:nth-child(odd){background:rgba(0,0,0,.05);}
table tr:hover{background:rgba(0,0,0,.05);}
table input{background:none;text-align:center;max-width:200px;}
right_box{position:fixed;width:500px;height:100vh;background:#fff;z-index:10000;right:-100vw;top:0;padding-top:50px;padding-bottom:10px;box-shadow:0px -3px 8px 5px rgba(38,47,62,.3);}
right_box handle{position:absolute;width:100%;height:50px;line-height:50px;background:#262F3E;color:#fff;top:0;left:0;padding-left:20px;padding-right:10px;}
right_box handle text{float:left;font-size:17px;font-weight:bold;}
right_box handle icon{float:right;font-size:26px !important;cursor: pointer;}
right_box handle icon:hover{color:crimson;}
right_in_box{float:left;width:100%;padding:10px;padding-bottom:40px;overflow:hidden;height:100%;overflow-y:auto;}
right_in_box::-webkit-scrollbar{width:5px;background:rgba(255,255,255,.5);border-radius:5px}
bg{position:fixed;width:100%;height:100vh;left:0;top:0;background:rgba(0,0,0,0.5);z-index:1000;display:none;}
.right_show{right:0}

win{position:fixed;width:600px;z-index:100000;top:100px;left:500px;background:#fff;box-shadow:0 2px 4px 0 rgb(54 58 80 / 32%);padding-top:40px;}
win handle{position:absolute;width:100%;height:40px;background:#262F3E;color:#fff;top:0;left:0;line-height:40px;}
win handle text{float:left;width:100%;padding-left:20px;font-size:17px;}
win handle icon{position:absolute;right:10px;font-size:24px !important;}
win handle icon:hover{color:crimson;}
win win_box{float:left;width:100%;padding:10px;font-size:14px;min-height:20vh;max-height:60vh;overflow:hidden;overflow-y:auto;}
win handle:hover{background:#006eff}


l{float:left;width:100%;padding-left:70px;min-height:40px;margin-bottom:8px;}
l text{position:absolute;left:0;top:0;line-height:40px;font-size:14px;}
l input{float:left;width:100%;background:#efefef;padding-left:8px;padding-right:8px;border-radius:5px;height:40px;font-size:14px}
l .need{background:rgba(255,0,0,.1)}
l a{float:left;padding-left:20px;padding-right:20px;height:40px;line-height:40px;margin-right:8px;background:#efefef;border-radius:5px;}
l .select{background:#006eff;color:#fff;}
l .bt{float:left;padding-left:25px;background:#262F3E;color:#fff;padding-right:25px;margin-right:8px;height:45px;line-height:45px;}
l .bt:hover{background:#000}

msg{position:fixed;width:100%;height:0px;top:0;z-index:1000000;left:0;padding-left:50%;}
msg msg_box{float:left;opacity:0;font-size:15px;line-height:24px;width:400px;margin-left:-200px;padding:20px;background:#fff;margin-top:-200px;box-shadow:0 2px 4px 0 rgb(54 58 80 / 32%);}
msg text{float:left;width:100%;}
msg .icon-close{position:absolute;top:0px;right:3px;font-size:20px !important;}
msg .icon-close:hover{color:crimson;}
.msg_show{margin-top:30px !important;opacity:1 }
err{color:crimson;font-size:15px}
box{padding:10px;box-shadow:0 2px 4px 0 rgb(54 58 80 / 32%);background:#fff;float:left;width:100%;}
box b{float:left;width:100%;height:20px;line-height:20px;font-size:15px;}

help{float:left;width:100%;padding:10px;background:rgba(44,186,85,.1);line-height:16px;margin-top:10px;font-size:11px;}
switch x{position:absolute;z-index:1;top:2px;left:2px;width:28px !important;height:28px !important;-webkit-transition:.2s ease-in-out;transition:.2s ease-in-out;-webkit-transition-property:-webkit-transform,width,left;transition-property:transform,width,left;border-radius:16px;background-color:#fff;background-clip:padding-box;-webkit-box-shadow:0 2px 5px rgba(0,0,0,.4);box-shadow:0 2px 5px rgba(0,0,0,.4)}
switch{float:left;width:70px;height:36px;position:relative;background:#fff;border-radius:20px;border:#ddd 2px solid;cursor:pointer;margin-top:2px;}
.switch_select,.switch_true{border:#006eff 2px solid !important;background:#006eff;}
.switch_select x,.switch_true x{right:2px !important;left:auto;}

bottom_msg{position:fixed;width:360px;z-index:100000;right:0px;bottom:0px;max-height:50vh;overflow:hidden;overflow-y:auto;padding-top:40px}
bottom_msg::-webkit-scrollbar-thumb{width:3px;}
bottom_msg::-webkit-scrollbar{width:3px;}
bottom_msg box{margin-bottom:10px;}
bottom_msg index{margin-top:5px;}
bottom_msg index a{height:28px;line-height:28px;}
bottom_msg info{float:left;width:100%;color:#666}
bottom_msg .icon-close{position:absolute;right:0;}
bottom_msg in_box{float:left;width:100%;display:flex;flex-direction:column-reverse;}

nav_adm{float:right;color:#fff;font-size:16px;}
nav_adm username{float:left;margin-right:10px;}
nav_adm icon{float:left;font-size:20px !important;margin-left:10px;width:30px;text-align:center;}
nav_adm icon:hover{color:crimson;}
pre{white-space: pre-wrap;word-wrap: break-word;float:left;padding:0;float:left;width:100%;margin:0;margin-top:5px;font-size:15px;}
gg{position:absolute;right:0;top:50px;z-index:1000;height:50px;line-height:50px;width:500px;overflow:hidden;}
gg in_box{float:left;width:100%;height:50px;line-height:50px;color:crimson;}
gg gg_item{float:left;width:500px;padding-left:10px;padding-right:10px;overflow:hidden;height:50px;line-height:50px;}
.input_err{background:rgba(255,0,0,.1)}
</style>

<body>
<nav>
<logo onclick="go_url($(this))" href="./" style="background:url(<?php echo $cfg['logo'];?>) no-repeat center;background-size:cover;"></logo>
<nav_title onclick="go_url($(this))" href="./"><?php echo $cfg['webname'];?></nav_title>
<adm_logo onclick="go_url($(this))" url="?url=set&left_c=set" style="background:url(<?php echo $cfg['logo']?>) no-repeat center;background-size:cover;" onmouseover="$('out_menu').show()"></adm_logo>

<nav_adm>
<username><?php echo $adm?$adm['username']:$user['nickname']?></username>
<icon class="icon icon-pinglun m" onclick="msg_show($(this))"></icon>
<icon class="icon icon-guanbi1 m" onclick="loginout($(this))"></icon>
</nav_adm>

</nav>


<left>
<?php $left_c=g('left_c');$left_s=g('left_s');
foreach($left as $k=>$v){
echo '<left_box class="'.($v['url']==$left_c?'is_select':'').'">';$icon='';
$ac='href="'.$v['u'].'?t='.time().'&url='.$v['url'].'&left_c='.$v['url'].'&'.$v['query'].'"';

echo '<a class="left_main m " '.$ac.'>
<icon class="icon '.$v['icon'].'"></icon>
<text class="m">'.$k.'</text>'.$icon.'</a>';
if($v['menu']){
foreach($v['menu'] as $m=>$n){
echo '<left_item class="'.($left_s==$m?'left_item_select':'').'" >
<a '.($n['url']?'href="?url='.$n['url'].'&left_c='.$v['url'].'&left_s='.$m.'&t='.time().'&'.$n['query'].'"':'').' '.($n['ac']?'onclick="'.$n['ac'].'"':'').'>'.$m.'</a></left_item>';
}

echo '<icon class="icon icon-chevron-down jt"></icon>';
}
echo '</left_box>';
}
?>
</left>

<main><main_box>
</main_box></main>


<right_box class="m">
<handle><text></text><icon class="icon icon-close" onclick="right_close($(this))"></icon></handle>
<right_in_box></right_in_box>
</right_box>


<msg><msg_box class="m"><text></text><icon class="icon icon-close" onclick="$('msg msg_box').removeClass('msg_show');"></icon></msg_box></msg>

<bg onclick="right_close($(this));win_close($(this))" ></bg>
<input type="file" id="up_img" accept="image/*" style="display:none;" name="up_img[]"  multiple="multiple">


<?php if($gg){?>
<gg><in_box style="width:<?php echo count($gg)*500?>px">
<?php foreach($gg as $v){echo '<gg_item onclick="gg_show($(this))" i="'.$v['id'].'">'.$v['title'].'</gg_item>';}?>
</in_box></gg>
<?php }?>
<script>
window.main_url='./<?php echo $url.'.php?'.$_SERVER['QUERY_STRING'];?>';
$(document).ready(function(){
main_load();
$('#up_img').change(function(e){get_up_img(e);});
//get_new_msg();

<?php if($gg){
echo 'window.gg_total='.count($gg).';';    
?>
window.gg_page=0;
window.gg_scroll = new IScroll("gg", {snap: true,scrollX: true,snapSpeed: 800,});

setInterval(function(){window.gg_page++;
if(window.gg_total==window.gg_page){window.gg_page=0;}
window.gg_scroll.goToPage(window.gg_page,0, 800);
},15000)
<?php }?>
});
function main_load(){
$('main_box').load(window.main_url);
}


function add_msg(d){
var h='<box class="m" id="msg_'+d.id+'"><b>'+d.c+'<icon class="icon icon-close" onclick="close_msg($(this))" i="'+d.id+'"></icon></b>';
h+='<info>'+(d.msg?d.msg:'')+'<br>日期:'+d.date+'</info>';
h+='<index><a class="b" onclick="view_msg($(this))" i="'+d.id+'">查看</a>';
if(d.latitude){
h+='<a class="b m" onclick="'+(d.latitude?'set_center('+d.latitude+','+d.longitude+')':'msg(\'改报警没有设置位置\');')+'">位置</a>';
}
h+='<a>附近数警</a>';
h+'</index></box>';
var obj=$('bottom_msg #msg_'+d.id);
if(obj.length>0){}else{
$('bottom_msg in_box').prepend(h);
}
}



function get_new_msg(){
if(!window.msg_last_id){window.msg_last_id=0;}
post('get_new_msg','',window.msg_last_id,function(res){
$('bottom_msg').prepend(res.html);
if(res.id){window.msg_last_id=res.id;}
setTimeout(function(){get_new_msg()},10000);
});
}

function view_msg(o){
var id=o.attr('i');if(!id){msg('请指定消息ID');return;}
right({title:'查看警情',url:'msg/detail.php?id='+id,width:'600px'})
}

function set_center(lat,lng,c){
if(!lat || !lng){return;}
if(!window.map){return;}
lat=parseFloat(lat);
lng=parseFloat(lng)+0.002;
var center = new TMap.LatLng(lat,lng);
window.map.panTo(center);    
}

function close_msg(o){
var id=o.attr('i');if(!id){return;}
post('msg_is_read','',id,function(res){
$('#msg_'+id).fadeOut(200);
});
}


function chat(o){
var id=o.attr('i');if(!id){id=0;}
right({title:'查看留言',url:'chat.php?id='+id,width:'500px'})
}

function no_login(){location.href="login.php";}

function loginout(){
if(!confirm("是否退出登录?")){return;}
post('loginout','','',function(res){
   no_login(); 
});

}



function win(d){
var width=d.width;
var w=$(window).width();
var left=Math.ceil((w-width)/2);
if(d.id){
$('#'+d.id).remove();
}else{var id=(new Date()).getTime();d.id='win_'+id;}
var h='<win id="'+d.id+'" style="left:'+left+'px;width:'+d.width+'px"><handle class="m"><text>'+(d.title?d.title:'新窗口')+'</text><icon class="icon icon-close" onclick="win_close($(this))" i="'+d.id+'"></icon></handle>';
h+='<win_box></win_box>';
h+='</win>';

$('body').append(h);
$('#'+d.id).draggable({handle:$('#'+d.id+' handle')});

if(d.html){$('#'+d.id+' win_box').html(d.html);}
if(d.url){$('#'+d.id+' win_box').load(d.url);}
if(d.bg==1){$('bg').show();$('bg').attr('i',d.id);}
}

function win_close(o){
var id=o.attr('i');
if(id){
$('#'+id).remove();
}else{
$('win').remove();
}
$('bg').hide();
}


function right(d){
if(!d.title){d.title='新窗口';}
$('right_box handle text').html(d.title);
if(d.width){$('right_box').width(d.width);}
if(d.html){$('right_box right_in_box').html(d.html);}
if(d.url){right_load(d.url);}
$('right_box').addClass('right_show');
if(d.bg!=1){$('bg').show();}
}

function right_reload(){
right_load(window.right_url);
}

function right_load(url){
$('right_box right_in_box').load(url,function(){
window.right_url=url;
$('right_box right_in_box input').each(function(){
var need=$(this).attr('need');
if(need==1){
$(this).attr('onblur','check_null($(this))');
$(this).attr('onkeydown','check_null($(this))');
}
});
});
}

function right_close(){
$('right_box').removeClass('right_show');
$('bg').hide();
$('right_box right_in_box').html('');
}

function check_null(o){
var val=o.val();
if(!val){o.addClass('need');}else{o.removeClass('need');}
}

function post(ac,data,id,callback){
if(data){console.log(data,id,ac);}
$.post('ac.php',{ac:ac,data:data?JSON.stringify(data):'',id:id?id:0},function(res){
    var d=json(res,1);
    if(d.err=='ok'){
    callback(d);
    }else{
    if(d.err=='no_login'){no_login();return;}
    msg(d.err);
    }
    
});    

}

function form_data(obj){
var data={};var can=0;
obj.each(function(){
var c=$(this).attr('c');
var val=$(this).val();
var need=$(this).attr('need');
var t=$(this).attr('t');
if(!t){t=$(this).attr('placeholder');}
$(this).removeClass('input_err');
if(need==1 && !val){msg(t+'不能为空');can++;
$(this).addClass('input_err');
return;}
data[[c]]=val;
})
var re={data:data,can:can};
console.log(re);
return re;
}



function msg(str){
$('msg text').html(str);
$('msg msg_box').addClass('msg_show');
clearTimeout(window.msg_time);
window.msg_time=setTimeout(function(){$('msg msg_box').removeClass('msg_show');},5000);
}


function get_up_img(e){//上传图片
window.img_data={};window.read_up_img=0;
var max=10;
var num=e.target.files.length;
if(num>max){msg('抱歉，您最多一次上传'+max+'张图片');return;}

if(num>0){
window.up_img_num=num;
for(var i=0;i<=num-1;i++){
var file = e.target.files[i];//图片文件
console.log(e.target.files[i]);
read_file(file,i);
}
}else{msg('请选择图片');}//格式不正确

msg('图片上传中，请稍后...');
$('#up_img').val('');
window.read_time=1;
setTimeout("img_upload();",500);
}


function read_file(file,i){
window.read_up_img++;
var max_size=1024*1024*5;//20K
var big_size=1024*1024*5;
var type=file.type;
var size=file.size;
var name=file.name;
var ext='';
var can=1;
var text='上传中，请稍后';
if (type=='image/jpeg' || type=='image/png' || type=='image/webp'){
switch(type){
case 'image/jpeg':ext='jpg';break;
case 'image/png':ext='png';break;
case 'image/webp':ext='webp';break;
}
if(size>max_size){msg(name+'图片尺寸太大了');can=0;text='图片尺寸太大';}
var freader = new FileReader();
freader.readAsDataURL(file);
//读取图片数据
freader.onload=function(e){//读取完成
if(size>big_size){msg(name+'图片文件超过上传尺寸');can=0;text='图片尺寸太大';}
window.img_data['item_'+i]={name:name,type:type,size:size,ext:ext,data:this.result,can:can,ac:'img_up',item:'img_item_'+i}
var h='<img_item  ><item><img class="img" src="'+this.result+'"  id="img_item_'+i+'"><span class="can_up_'+can+'">'+text+'</span></item></img_item>';
$('img_list').prepend(h);
}

}else{msg(name+'文件格式不正确，无法上传');}

}



function img_upload(){//获取图片并上传
if(window.read_up_img==window.up_img_num && window.img_data){
console.log('图片完全读取完成',window.img_data);
console.log('开始上传图片');
$.each(window.img_data,function(i,n){
console.log('正在上传'+n.name);
$.ajax({
type:'POST',
url:'<?php echo $cfg['upload'];?>',
timeout:120000,
data:n,
contentType:'application/x-www-form-urlencoded',
success:function(res){
var d=json(res,1);
if(d.err=='ok'){//alert(n.item)
var obj=$('#'+n.item);
obj.parent().find('span').addClass('is_up');
obj.parent().find('span').html('上传成功');

obj.attr('src',d.img_480);
obj.attr('img',d.img);
obj.attr('img_240',d.img_240);
obj.attr('img_750',d.img_750);
obj.attr('img_480',d.img_480);
obj.attr('img_1080',d.img_1080);
var ac=$('img_list').attr('ac');
if(ac){obj.attr('onclick',ac);}

}else{
msg(d.err);
}

}

});

})

}else{
window.read_time++;
if(window.read_time>10){return;}
setTimeout("img_upload();",500);
}
}




function go_url(o){
var url=o.attr('url');
if(!url){var url=o.attr('href');}
if(!url){return;}
location.href=url;
}

function gg_show(o){
var id=o.attr('i');if(!id){msg('请指定公告');return;}
right({title:'查看警务公告',url:'msg/gg.php?id='+id,width:'600px'})
}




</script>
</body>
</html>